package top.humbleyuan.enum_demo;

/**
 * @Author HumbleYuan
 * @Date 2020/2/7 13:30
 * @Des 枚举相当于内置的数据库或者配置文件
 */
public enum  EnumDemo {
    ONE(1,"Ashe"), TWO(2, "Janna"), THREE(3, "Diana");

    private Integer id;
    private String heroName;

    EnumDemo(Integer id, String heroName) {
        this.id = id;
        this.heroName = heroName;
    }

    // 根据id获取英雄名
    public static String getEntityById(int index) {
        EnumDemo[] enumDemos =  EnumDemo.values();

        for (EnumDemo e:enumDemos) {
            if(index == e.getId()) {
                return e.getHeroName();
            }
        }

        return null;
    }

    public Integer getId() {
        return id;
    }

    public String getHeroName() {
        return heroName;
    }
}
